/*
 * COPYRIGHT. HSBC HOLDINGS PLC 2016. ALL RIGHTS RESERVED.
 * 
 * This software is only to be used for the purpose for which it has been
 * provided. No part of it is to be reproduced, disassembled, transmitted,
 * stored in a retrieval system nor translated in any human or computer
 * language in any way or for any other purposes whatsoever without the
 * written consent of HSBC Holdings plc.
 */
package com.pactera.integral.security.filter;

import javax.servlet.http.HttpServletRequest;

import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;

import com.pactera.integral.security.authentication.TokenAuthenticationService;

/**
 * The class PreAuthenticatedProcessingFilter.
 */
public class PreAuthenticatedProcessingFilter extends AbstractPreAuthenticatedProcessingFilter {

    /**
     * @param request request
     * @return Acteur
     * @see org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter#getPreAuthenticatedPrincipal(javax.servlet.http.HttpServletRequest)
     */
    @Override
    protected Object getPreAuthenticatedPrincipal(final HttpServletRequest request) {
        Authentication authentication = TokenAuthenticationService.getAuthentication((HttpServletRequest) request);
        return authentication != null ? authentication.getPrincipal() : null;

    }

    /**
     * @param request request
     * @return CWDID
     * @see org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter
     *      #getPreAuthenticatedCredentials(javax.servlet.http.HttpServletRequest)
     */
    @Override
    protected Object getPreAuthenticatedCredentials(final HttpServletRequest request) {

        return "N/A";
    }

}
